import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { UserForm, UserInfo, UserPageVO, UserQuery, roleAll } from "./types";

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfo(data: any): AxiosPromise<UserInfo> {
  return request({
    url: "/admin/rbac/manager/currManagerInfo",
    method: "post",
    data
  });
}

/**
 * 获取角色列表
 */
export function postRoleAll(): AxiosPromise<roleAll> {
  return request({
    url: "/admin/rbac/role/all",
    method: "post",
  });
}

// 新增管理员
export function postAdminAdd(data: any) {
  return request({
    url: "/admin/rbac/manager/add",
    method: "post",
    data
  });
}

/**
 * 新增角色
 */
export function postRoleAdd(data: any) {
  return request({
    url: "/admin/rbac/role/add",
    method: "post",
    data
  });
}

/**
 * 新增角色
 */
export function postRoleInfo(data?: any) {
  return request({
    url: "/admin/rbac/role/detail",
    method: "post",
    data
  });
}

/**
 * 删除角色
 */
export function postRoleDel(data: any) {
  return request({
    url: "/admin/rbac/role/del",
    method: "post",
    data
  });
}

/**
 * 修改角色
 */
export function postRoleEdit(data: any) {
  return request({
    url: "/admin/rbac/role/update",
    method: "post",
    data
  });
}

// 添加权限
export function postBindRoutes(data: any) {
  return request({
    url: "/admin/rbac/role/bindRoutes",
    method: "post",
    data
  });
}


// 修改管理员
export function postAdminInfo(data: any) {
  return request({
    url: "/admin/rbac/manager/update",
    method: "post",
    data
  });
}


// 删除管理员
export function postAdminDel(data: any) {
  return request({
    url: "/admin/rbac/manager/del",
    method: "post",
    data
  });
}

// 修改登录密码
export function updateLoginPwd(data: any) {
  return request({
    url: "/admin/rbac/manager/updateLoginPwd",
    method: "post",
    data
  });
}


/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
  queryParams: UserQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: "/admin/rbac/manager/pageList",
    method: "post",
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: number): AxiosPromise<UserForm> {
  return request({
    url: "/api/v1/users/" + userId + "/form",
    method: "get",
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: "/api/v1/users",
    method: "post",
    data: data,
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(id: number, data: UserForm) {
  return request({
    url: "/api/v1/users/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 修改用户状态
 *
 * @param id
 * @param status
 */
export function updateUserStatus(id: number, status: number) {
  return request({
    url: "/api/v1/users/" + id + "/status",
    method: "patch",
    params: { status: status },
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: number, password: string) {
  return request({
    url: "/api/v1/users/" + id + "/password",
    method: "patch",
    params: { password: password },
  });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string) {
  return request({
    url: "/api/v1/users/" + ids,
    method: "delete",
  });
}

/**
 * 下载用户导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return request({
    url: "/api/v1/users/template",
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导出用户
 *
 * @param queryParams
 * @returns
 */
export function exportUser(queryParams: UserQuery) {
  return request({
    url: "/api/v1/users/_export",
    method: "get",
    params: queryParams,
    responseType: "arraybuffer",
  });
}

/**
 * 导入用户
 *
 * @param file
 */
export function importUser(deptId: number, file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/api/v1/users/_import",
    method: "post",
    params: { deptId: deptId },
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 质押机器人-分页列表
 */
export function pledgeRobotList(params: any) {
  return request({
    url: "/admin/store/pledgeRobot/pageList",
    method: "post",
    data: params,
  });
}

/**
 * 质押机器人-添加
 */
export function pledgeRobotAdd(params: any) {
  return request({
    url: "/admin/store/pledgeRobot/add",
    method: "post",
    data: params,
  });
}

/**
 * 质押机器人-修改售卖状态
 */
export function updateEnableSale(params: any) {
  return request({
    url: "/admin/store/pledgeRobot/updateEnableSale",
    method: "post",
    data: params,
  });
}

/**
 * 质押机器人-删除
 */
export function pledgeRobotDel(params: any) {
  return request({
    url: "/admin/store/pledgeRobot/del",
    method: "post",
    data: params,
  });
}

/**
 * 质押机器人-更新
 */
export function pledgeRobotUpdate(params: any) {
  return request({
    url: "/admin/store/pledgeRobot/update",
    method: "post",
    data: params,
  });
}

/**
 * 充值钱包-分页列表
 */
export function rechargeWalletList(params: any) {
  return request({
    url: "/admin/member/rechargeWallet/pageList",
    method: "post",
    data: params,
  });
}

/**
 * 充值钱包-添加
 */
export function rechargeWalletAdd(params: any) {
  return request({
    url: "/admin/member/rechargeWallet/add",
    method: "post",
    data: params,
  });
}

/**
 * 充值钱包-更新
 */
export function rechargeWalletUpdate(params: any) {
  return request({
    url: "/admin/member/rechargeWallet/update",
    method: "post",
    data: params,
  });
}

/**
 * 充值钱包-删除
 */
export function rechargeWalletDel(params: any) {
  return request({
    url: "/admin/member/rechargeWallet/del",
    method: "post",
    data: params,
  });
}

/**
 * 修改用户基础信息
 */
export function userUpdateBase(params: any) {
  return request({
    url: "/admin/member/user/updateBase",
    method: "post",
    data: params,
  });
}

/**
 * 用户详情
 */
export function userDetail(params: any) {
  return request({
    url: "/admin/member/user/detail",
    method: "post",
    data: params,
  });
}